const app = getApp();
import HttpRequst from '../../../utils/httpRequst.js'
import API from '../../../utils/config.js'
import upng from "../../../utils/UPNG.js"
import SendFormId from '../../../utils/sendFormId.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
     isAjaxing:false,
     isSigned:false,
     testSrc:"",
     htInfo:"",
     dataInfo:"" //存放用户信息的
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
   
      this.setData({
        dataInfo: options,
      });
    HttpRequst(true, API.createcontarct, 1, app.getUkey(), "", "POST", false, function (res) {
      
      that.setData({
        htInfo: res.data
      })
    });
  },

  

  

  
 
  goToSeeHt: function () {
    wx.downloadFile({
      url: this.data.htInfo.url,
      success: function (res) {
        var filePath = res.tempFilePath
       
        wx.openDocument({
          filePath: filePath,
          success: function (res) {
            
          }
        })
      }
    })
  },

  previewImage: function (e) {
    wx.previewImage({
      current: this.data.htInfo.imgs[0], // 当前显示图片的http链接
      urls: this.data.htInfo.imgs // 需要预览的图片http链接列表
    })
  },
 
  formSubmit:function(e){
 
    var that=this;
    this.setData({
      isAjaxing:true
    });
    wx.showLoading()
    app.getFormIds(e.detail.formId);
    SendFormId(app, "POST", 2, "");
    HttpRequst(false, API.signcontarct, 1, app.getUkey(), { path: this.data.htInfo.path,sealData: this.data.dataInfo.base64src}, "POST", false, function (res) {
      wx.hideLoading();//隐藏提示框
      that.setData({
        isAjaxing: false
      })
      if (!res.status) {
        wx.showToast({
          title: res.msg,
          icon: 'none'

        });
      } else {
        wx.navigateTo({
          url: '/pages/index/mineht/mineht?fromwhere=sign',
        })
      }

    });
   
    
    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    if(this.data.dataInfo.fromwhere=="qianming"){
      wx.reLaunch({
        url: '/pages/index/index/index'
      })
      // wx.navigateBack({
      //   delta: 2
      // })
    }
    
   
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})